package com.lsfb.signln.Location.LocationSearch;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import com.lsfb.signln.R;
import com.zgscwjm.lsfbbasetemplate.adapter.CommonRecycAdapter;
import com.zgscwjm.lsfbbasetemplate.adapter.ViewHolderRecyc;

import java.util.List;

/**
 * Created by Administrator on 2018/2/7 0007.
 */

public class HorizontalTimerAdapter extends CommonRecycAdapter<String> {
    private Context mContext;
    private int curPosition = 0;

    private ItemCheckedListener listener;

    public interface ItemCheckedListener {
        void onChecked(String model, int position);
    }

    public HorizontalTimerAdapter(Context context, List<String> list, int layoutId, ItemCheckedListener listener) {
        super(context, list, layoutId);
        mContext = context;
        this.listener = listener;
    }

    @Override
    public void convert(final ViewHolderRecyc holder, final String model) {
        holder.setText(R.id.tv_date, model);

        final LinearLayout item_date = (LinearLayout) holder.getView(R.id.item_date);
        if (holder.getPosition() == curPosition) {
            item_date.setBackground(mContext.getResources().getDrawable(R.drawable.btn_bg_select));
        } else {
            item_date.setBackgroundColor(mContext.getResources().getColor(R.color.white_color));
        }

        holder.setOnclick(R.id.item_date, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    curPosition = holder.getPosition();
                    listener.onChecked(model, curPosition);
                }
            }
        });
    }
}
